const Navigation = require("../model/Navigation");

/**
 * 分类标签中间件
 */
module.exports = {
    /**
     * 获取分类标签
     */
    getWebPageList: (req, res, next) => {
        Navigation.getNavigation()
            .then((res) => {
                req.webPageList = res;
                next();
            })
            .catch((err) => {
                next(err);
            });
    },
    // 获取指定分类标签
    getWebPageId: (req, res, next) => {
        // 获取地址栏传递的id值
        let id = req.query.id
        Navigation.getWebPageId(id)
            .then((res) => {
                req.webPageInfo = res;
                next();
            })
            .catch((err) => {
                next(err);
            });
    },
    // 获取指定分类标签
    updateStatus: (req, res, next) => {
        // 获取地址栏传递的id值
        const { status, id } = req.query
        Navigation.updateStatus({ id, status })
            .then((resolve) => {
                req.affectedRows = resolve;
                next();
            })
            .catch((err) => {
                next(err);
            });
    }
};
